package cn.zqy.demo2.day04.demo03;


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

/*
* 斗地主综合案例:有序版本
    1.准备牌
    2.洗牌
    3.发牌
    4.排序
    5.看牌
* */
public class Demo02DouDiZhuSort {
    public static void main(String[] args) {
        // 1.准备牌
        HashMap<Integer, String> poker = new HashMap<>();
        ArrayList<Integer> pokerIndex = new ArrayList<>();
        String[] color = new String[]{"♠", "♥", "♣", "♦"};
        String[] numbers = new String[]{"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};

        ArrayList<Integer> player01 = new ArrayList<>();
        ArrayList<Integer> player02 = new ArrayList<>();
        ArrayList<Integer> player03 = new ArrayList<>();
        ArrayList<Integer> dipai = new ArrayList<>();

        // 把大小王放进去
        int index = 0;
        poker.put(index, "大王");
        pokerIndex.add(index++);
        poker.put(index, "小王");
        pokerIndex.add(index++);

        for (String i : numbers) {
            for (String j : color) {
                poker.put(index, j + i);
                pokerIndex.add(index++);
            }
        }

        // 输出牌
        System.out.println(poker);
        System.out.println(pokerIndex);

        // 2.洗牌
        Collections.shuffle(pokerIndex);

        // 3. 发牌
        for (int i = 0; i < pokerIndex.size(); i++) {
            Integer in = pokerIndex.get(i);
            if (i >= 51) {
                dipai.add(in);
            } else if (i % 3 == 0) {
                player01.add(in);
            } else if (i % 3 == 1) {
                player02.add(in);
            } else if (i % 3 == 2) {
                player03.add(in);
            }
        }

        //4. 排序
        Collections.sort(player01);
        Collections.sort(player02);
        Collections.sort(player03);
        Collections.sort(dipai);

        // 5.看牌
        lookPoker("A", player01, poker);
        lookPoker("B", player02, poker);
        lookPoker("C", player03, poker);
        lookPoker("底牌", dipai, poker);
    }

    private static void lookPoker(String name, ArrayList<Integer> list, HashMap<Integer,String> map) {
        System.out.print(name + ": ");
        for (Integer i :list) {
            System.out.print(map.get(i) + "  ");
        }
        System.out.println();
    }


}
